#include "mediator.h"

void ConCreteMediator::registColleague(std::shared_ptr<Colleague> &colleague)
{
    m_colleagues.push_back(colleague);
}

void ConCreteMediator::ColleagueChanged(const std::string& msg,const std::shared_ptr<Colleague> &colleague)
{
    for(auto& col : m_colleagues ){
        if(col.get() != colleague.get())
        {
            col->recieve(msg);
        }
    }
}

void ConcreteCollegue::send(const std::string &msg)
{
   auto med = m_mediator.lock();
   med->ColleagueChanged(msg,shared_from_this());
}

void ConcreteCollegue::recieve(const std::string &msg)
{
    std::cout << "I am " << m_name <<",recieve "<< msg << std::endl;
}

